from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene
from core.action import Action
from items.uniform import Uniform
from core.support import get_game

class WardensOffice(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)
        self.safe_locked = True
        
        # add inventory items
        
        # build list of actions
        self.add_action(ExitOffice)
        self.add_action(OpenCloset)
        self.add_action(OpenSafe)
        self.add_action(ExamineMirror)
        self.add_action(ExamineRecordPlayer)
        self.add_action(ExamineDesk)
        self.add_action(SewUniform)
    
    def get_description(self):
        return "MacGyver quietly enters the warden's office.  A Johnny Cash record sits on the record player in the corner."
    
    def get_image(self):
        return 'wardens_office.jpg'


class WardensOfficeHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return WardensOffice


class ExamineMirror(Action):
    def __init__(self):
        Action.__init__(self, "ExamineMirror")

    def get_description(self):
        return "Examine Mirror"

    def do_action(self,game,room,request):
        set_cutscene("MacGyver saunters over to the mirror with one eyebrow raised.")
        return

    def get_destination(self):
        return 'mirror'

    def get_method(self):
        return "get"


class ExamineDesk(Action):
    def __init__(self):
        Action.__init__(self, "ExamineDesk")

    def get_description(self):
        return "Examine Desk"

    def do_action(self,game,room,request):
        set_cutscene("MacGyver sits down in the warden's chair, kicks his feet up onto the desk.")
        return

    def get_destination(self):
        return 'wardensdesk'

    def get_method(self):
        return "get"


class ExamineRecordPlayer(Action):
    def __init__(self):
        Action.__init__(self, "ExamineRecordPlayer")

    def get_description(self):
        return "Examine Record Player"

    def do_action(self,game,room,request):
        set_cutscene("MacGyver sings along with Johnny Cash as he moves closer to the record player.")
        return

    def get_destination(self):
        return 'recordplayer'

    def get_method(self):
        return "get"
    
class SewUniform(Action):
    def __init__(self):
        Action.__init__(self, "sew_uniform")
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Sew Guard Uniform"
    
    def do_action(self,game,room,request):
        if get_game().get_player().has_item('uniform1'):
            set_cutscene("MacGyver doesn't need two uniforms.")
        else:
            set_cutscene("MacGyver sews and puts on a guard uniform.")
            game.get_player().pop_item('cloth')
            game.get_player().pop_item('needle')
            game.get_player().pop_item('hair')
            game.get_player().add_item(Uniform('uniform2'))
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        return (player.has_item('cloth') and player.has_item('needle') and player.has_item('hair'))


class ExitOffice(Action):
    def __init__(self):
        Action.__init__(self, "ExitOffice")
    
    def get_description(self):
        return "Exit Office"

    def do_action(self,game,room,request):
        set_cutscene("MacGyver exits back into the hallway.")
        return
    
    def get_destination(self):
        return 'prisonhall'
    
    def get_method(self):
        return "get"

class OpenCloset(Action):
    def __init__(self):
        Action.__init__(self, "OpenCloset")
    
    def get_description(self):
        return "Open Closet"
    
    def get_destination(self):
        return 'closet'

    def get_method(self):
        return "get"
    

class OpenSafe(Action):
    def __init__(self):
        Action.__init__(self, "OpenSafe")
    
    def get_description(self):
        return "Open Safe"
    
    def get_destination(self):
        if self.room.safe_locked:
            return 'wardensoffice'
        else:
            #THE PLAYER NEEDS TO GET SOMETHING FROM THE SAFE?
            return 'wardensoffice'
    
    def do_action(self,game,room,request):
        if self.room.safe_locked:
            player = game.get_player()
            if 'keys' in player.inventory:
                set_cutscene("Your key seems to fit.  You slowly slide the safe door open.")
                self.room.safe_locked = False
            else:
                set_cutscene("You can't open the safe because it is locked.")
        else:
            set_cutscene("The safe is already wide open.")
        return
    
    def get_method(self):
        return "get"